import 'package:flutter/material.dart';
import '../errors/error_handler.dart';
import '../../shared/widgets/error_widget.dart';
import '../../shared/widgets/toast_helper.dart';

/// 扩展方法，方便在 BuildContext 中快速显示错误
extension ErrorHandlerExtension on BuildContext {
  /// 显示错误 Toast
  void showError(dynamic error) {
    final message = ErrorHandler.getErrorMessage(error);
    ToastHelper.showError(this, message);
  }
  
  /// 显示成功 Toast
  void showSuccess(String message) {
    ToastHelper.showSuccess(this, message);
  }
  
  /// 显示信息 Toast
  void showInfo(String message) {
    ToastHelper.showInfo(this, message);
  }

  /// 显示错误 Dialog
  Future<void> showErrorDialog(
    dynamic error, {
    String? title,
    VoidCallback? onConfirm,
  }) {
    return ErrorDialog.show(this, error, title: title, onConfirm: onConfirm);
  }

  /// 获取错误消息
  String getErrorMessage(dynamic error) {
    return ErrorHandler.getErrorMessage(error);
  }
}

